package android.pruebas.content1;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;

public class Content1Activity extends Activity {
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView texto = (TextView) findViewById(R.id.texto);

		Cursor cursor = getContactos();

		while (cursor.moveToNext()) {

			String nombre = cursor.getString(cursor
					.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
			texto.append("Nombre: ");
			texto.append(nombre);
			texto.append("\n");
		}
	}

	private Cursor getContactos() {

		// Realizar la consulta.
		Uri uri = ContactsContract.Contacts.CONTENT_URI;
		String[] projection = new String[] { ContactsContract.Contacts._ID,
				ContactsContract.Contacts.DISPLAY_NAME };
		String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
				+ ("1") + "'";
	
		selection = "";
		
		String[] selectionArgs = null;
		String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
				+ " COLLATE LOCALIZED ASC";

		
		return managedQuery(uri, projection, selection, selectionArgs,
				sortOrder);
	}

}
	